package com.ng.desktop.expansionsa.view.articulo;

import java.awt.Dimension;
import java.util.ArrayList;
import java.util.List;

import com.ng.desktop.expansionsa.model.Articulo;
import com.ng.desktop.expansionsa.persistence.ArticuloPersistence;
import com.ng.desktop.expansionsa.services.NGFactoryBean;
import com.ng.framework.persistence.NGSearchParameter.Type;
import com.ng.framework.persistence.NGSearchParameter.UnaryOperation;
import com.ng.framework.view.desktop.NGABMCFrame;
import com.ng.framework.view.desktop.NGGUIUtils;
import com.ng.framework.view.desktop.NGTablePanel;
import com.ng.framework.view.desktop.filters.NGFilter;
import com.ng.framework.view.desktop.filters.NGTextFieldFilter;

public class ArticuloFrame extends NGABMCFrame<Articulo, ArticuloPersistence> {

	private static final long serialVersionUID = -5032819694979782834L;
	
	private FilterCategoria filterCategoria;
	
	public ArticuloFrame() {
		this.setTitle("Gestión de Artículos");
		this.setFrameIcon(NGGUIUtils.getImageIcon("icons/drill.png"));
		this.setSize(new Dimension(755, 600));
		this.centrar();
	}

	@Override
	protected ArticuloPersistence createPersistence() {
		return (ArticuloPersistence) NGFactoryBean.getInstance().getBean("articuloPersistence");
	}

	@Override
	protected List<NGFilter> createFilters() {
		List<NGFilter> filters = new ArrayList<NGFilter>();
		
		filters.add(this.getFilterCategoria());
		filters.add(new NGTextFieldFilter("Descripción", Articulo.class, "descripcion", Type.STRING, UnaryOperation.LIKE));
		
		return filters;
	}
	
	private FilterCategoria getFilterCategoria() {
		if(filterCategoria == null) {
			filterCategoria = new FilterCategoria();
		}
		
		return filterCategoria;
	}

	@Override
	protected NGTablePanel<Articulo, ArticuloPersistence> createTable(
			ArticuloPersistence persistence) {
		return new ArticuloTablePanel(persistence, this.getFilterCategoria());
	}

}
